package com.lhy.skywalking.demo.controller;

import com.lhy.skywalking.demo.service.TraceService;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.toolkit.trace.TraceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@RestController
@RequestMapping("/trace")
@Slf4j
public class TraceController {

    @Autowired
    private TraceService traceService;

    @GetMapping
    public String index() {
        Optional<String> putCorrelation = TraceContext.putCorrelation("name", "张芝山");
        log.info("[自定义追踪测试] 存储标签信息：{}", putCorrelation.orElse(null));
        traceService.payOrder("订单");
        return "success";
    }
}
